<template>
	<view :class="productConClass">
		<view v-if="storeInfo.id">
			<!-- 轮播图 -->
			<product-con-swiper :img-urls="storeInfo.sliderImageArr"></product-con-swiper>

			<!-- 商品信息描述 -->
			<view class="wrapper">
				<view class="share acea-row row-between row-bottom">
					<view class="money font-color-red">
						<!-- 零售价：otPrice 会员价：price 商家价： cost 服务商价： servicePrice -->
						<text>￥</text>

						<text class="num"
							v-if="userInfo.roleIdentification=='investment'||userInfo.roleIdentification=='store_administrator'||(userInfo.roleIdentification=='marketing_personnel'&&userInfo.roleLevel==1) ">{{storeInfo.merchantsPrice}}</text>
						<text class="num"
							v-if="userInfo.roleIdentification == 'dealer'||(userInfo.roleIdentification=='marketing_personnel'&&userInfo.roleLevel==2)">{{storeInfo.businessPrice}}</text>
						<text class="num"
							v-if="userInfo.roleIdentification == 'wholesaler'||(userInfo.roleIdentification=='marketing_personnel'&&userInfo.roleLevel==3)">{{storeInfo.wholesalePrice}}</text>
						<text class="num"
							v-if="userInfo.roleIdentification == 'group'||(userInfo.roleIdentification=='marketing_personnel'&&userInfo.roleLevel==4)">{{storeInfo.grouponPrice}}</text>
						<text class="num" v-if="userInfo.roleIdentification == 'member'">{{storeInfo.price}}</text>


						<uni-tooltip placement="top" v-if="userInfo.roleIdentification != 'member'"
							style="display: inline-block; width: 300rpx; font-weight: normal;">
							<uni-icons type="info" size="14"
								style="color: red;font-size: 14px;font-weight: normal;padding: 10rpx 20rpx;"></uni-icons>
							<template v-slot:content>
								<view class="uni-stat-tooltip">
									<view v-if="userInfo.roleIdentification=='investment'||userInfo.roleIdentification=='store_administrator'||(userInfo.roleIdentification=='marketing_personnel'&&userInfo.roleLevel==1)">
										招商价：￥{{storeInfo.merchantsPrice}}
									</view>
									<view v-if="userInfo.roleIdentification=='investment'||userInfo.roleIdentification=='store_administrator'||userInfo.roleIdentification == 'dealer'||(userInfo.roleIdentification=='marketing_personnel'&&userInfo.roleLevel<=2)">
										经销商价：￥{{storeInfo.businessPrice}}
									</view>
									<view v-if="userInfo.roleIdentification=='investment'||userInfo.roleIdentification=='store_administrator'||userInfo.roleIdentification == 'dealer'||userInfo.roleIdentification == 'wholesaler' ||(userInfo.roleIdentification=='marketing_personnel'&&userInfo.roleLevel<=3)">
										批发商价：￥{{storeInfo.wholesalePrice}}
									</view>
									<view v-if="userInfo.roleIdentification=='investment'||userInfo.roleIdentification=='store_administrator'||userInfo.roleIdentification == 'dealer'||userInfo.roleIdentification == 'wholesaler'||userInfo.roleIdentification == 'group'||(userInfo.roleIdentification=='marketing_personnel'&&userInfo.roleLevel<=4)">
										团购价：￥{{storeInfo.grouponPrice}}
									</view>
									<view >
										会员价：￥{{storeInfo.price}}
									</view>
								</view>
							</template>
						</uni-tooltip>

						<text style="font-size: 12px; padding: 0 10rpx;"
							v-if="userInfo.roleLevel == 1 && userInfo.isVip && storeInfo.isOneDiscount">会员享88折</text>



						<!-- 服务商看到的价格 服务商用会员价格展示 -->
						<!-- <text v-if="userInfo.roleLevel == 3" class="num">{{ storeInfo.price }}</text>
			<uni-tooltip v-if="userInfo.roleLevel == 3" placement="top" style="display: inline-block; width: 300rpx; font-weight: normal; padding: 10rpx;">
				<uni-icons type="info" size="14" style="color: red;font-size: 14px;font-weight: normal;padding: 0 20rpx;"></uni-icons>
				<template v-slot:content>
					<view class="uni-stat-tooltip">
						会员价：{{storeInfo.price}}<br>
						商家价：{{storeInfo.cost}}
					</view>
				</template>
			</uni-tooltip> -->

					</view>
					<view class="iconfont icon-fenxiang" @click="_listenerActionSheet"></view>
				</view>
				<view class="introduce" style="display: flex;align-items: center;">
					<!-- 商品分类 直营或者商家商品 -->
					<!-- <view class="uni-tag-btn"v-if="!storeInfo.merId" style="margin: 0 20rpx; width: 100rpx; text-align: center;">
				直营
			</view> -->

					{{ storeInfo.storeName }}
				</view>
				<view class="label acea-row row-between-wrapper">
					<!-- <text>原价:￥{{ storeInfo.otPrice }}</text> -->
					<text>库存:{{ storeInfo.stock }}</text>
					<!-- {{ storeInfo.unitName }} -->
					<text>销量:{{ storeInfo.sales }}</text>
				</view>
				<view class="coupon acea-row row-between-wrapper" @click="couponTap" v-if="couponList.length">
					<text class="hide line1 acea-row">
						<text>优惠券：</text>
						<text class="activity" v-for="(item, couponListEq) in couponList"
							:key="couponListEq">满{{ item.use_min_price }}减{{ item.coupon_price }}</text>
					</text>
					<view class="iconfont icon-jiantou"></view>
				</view>
			</view>

			<!-- 商家卡片 -->
			<BussinessCard :detail="BussinessDetails" :ids="merId"></BussinessCard>

			<!-- 运费 -->
			<div v-if="userInfo.roleIdentification != 'store_administrator' && userInfo.roleIdentification != 'marketing_personnel'" class="attribute acea-row row-between-wrapper">
				<div>
					运费：
					<span class="atterTxt">{{ tempName }}</span>
				</div>
			</div>

			<!-- 规格 -->
			<view v-if="userInfo.roleIdentification != 'store_administrator' && userInfo.roleIdentification != 'marketing_personnel'" class="attribute acea-row row-between-wrapper" @click="selecAttrTap">
				<view>
					<text>{{ attrTxt }}：</text>
					<text class="atterTxt">{{ attrValue }}</text>
				</view>
				<view class="iconfont icon-jiantou"></view>
			</view>

			<!-- 门店信息 -->
			<!-- <view class="store-info" v-if="systemStore">
        <view class="title acea-row row-between-wrapper">
          <view>门店信息</view>
          <text @click="goStoreList()" class="praise">
            更多
            <text class="iconfont icon-jiantou"></text>
          </text>
        </view>
        <view class="info acea-row row-between-wrapper">
          <view class="picTxt acea-row row-between-wrapper">
            <view class="pictrue">
              <image :src="systemStore.image" />
            </view>
            <view class="text">
              <view class="name line1">{{ systemStore.name }}</view>
              <view class="address acea-row row-middle">
                <text class="addressTxt">{{systemStore.address}}</text>
                <text class="iconfont icon-youjian"></text>
              </view>
            </view>
            <view class="addressBox">
              <a class="iconfont icon-dadianhua01 font-color-red phone" @click="telPhone(systemStore.phone)"></a>
              <view class="addressTxt corlor-yshop">距离{{systemStore.distance}}千米</view>
            </view>
          </view>
        </view>
      </view> -->

			<!-- 用户评价 -->
			<view class="userEvaluation" v-if="replyCount">
				<view class="title acea-row row-between-wrapper">
					<view>用户评价({{ replyCount }})</view>
					<text @click="goEvaluateList(id)" class="praise">
						<text class="font-color-red">{{ replyChance }}%</text>好评率
						<text class="iconfont icon-jiantou"></text>
					</text>
				</view>
				<user-evaluation :reply="reply"></user-evaluation>
			</view>

			<!-- 商品推荐 -->
			<!-- <view class="superior">
        <view class="title acea-row row-center-wrapper">
          <image src="https://qny.yijiumy.com/ling.png" />
          <text class="titleTxt">优品推荐</text>
          <image src="https://qny.yijiumy.com/ling.png" />
        </view>
        <template>
          <view class="slider-banner banner">
            <swiper :options="swiperRecommend" v-if="goodList.length > 0">
              <swiper-slide v-for="(item, eq2) in goodList" :key="eq2">
                <view class="list acea-row row-middle">
                  <view class="item" v-for="val in item.list" :key="val.image">
                    <view class="pictrue">
                      <image :src="val.image" />
                    </view>
                    <view class="name line1">{{ val.store_name }}}</view>
                    <view class="money font-color-red">¥{{ val.price }}</view>
                  </view>
                </view>
              </swiper-slide>
              <view class="swiper-pagination" slot="pagination"></view>
            </swiper>
          </view>
        </template>
      </view> -->

			<!-- 商品详情 -->
			<view class="product-intro">
				<!-- <text class="title">产品介绍</text> -->
				<view class="conter" v-html="storeInfo.description"></view>
			</view>
			<view style="height:100rpx;" v-if="userInfo.roleIdentification!='store_administrator'&&userInfo.roleIdentification!='marketing_personnel'"></view>
			<!-- 操作栏 -->
			<view class="footer acea-row row-between-wrapper"   v-if="userInfo.roleIdentification != 'store_administrator' && userInfo.roleIdentification != 'marketing_personnel'">
				<!-- #ifdef MP-WEIXIN -->
				<view class="item">
					<button open-type="contact" class='contacButton'>
						<view style="padding-bottom: 8rpx;" class="item">
							<view class="iconfont icon-kefu"></view>
							<text>客服</text>
						</view>
					</button>
				</view>
				<!-- #endif -->
				<view class="item" @click="goHome">
					<view class="iconfont icon-shouye-xianxing"></view>
					<text>首页</text>
				</view>
				<view class="item" @click="setCollect" v-if="storeInfo.userCollect">
					<view class="iconfont icon-shoucang1"></view>
					<text>收藏</text>
				</view>
				<view class="item" @click="setCollect" v-if="!storeInfo.userCollect">
					<view class="iconfont icon-shoucang"></view>
					<text>收藏</text>
				</view>
				<view @click="goShoppingCart()" v-if="animated" class="item animated bounceIn">
					<view class="iconfont icon-gouwuche1">
						<text class="num bg-color-red" v-if="CartCount > 0">{{CartCount}}</text>
					</view>
					<text>购物车</text>
				</view>
				<view @click="goShoppingCart()" class="item animated" v-if="!animated">
					<view class="iconfont icon-gouwuche1">
						<text class="num bg-color-red" v-if="CartCount > 0">{{CartCount}}</text>
					</view>
					<text>购物车</text>
				</view>
				<view class="bnt acea-row">
					<view class="joinCart" @click="joinCart">
						<text>加入购物车</text>
					</view>
					<view class="buy" @click="tapBuy">
						<text>立即购买</text>
					</view>
				</view>
			</view>

			<!-- 优惠券 -->
			<CouponPop v-on:changeFun="changeFun" :coupon="coupon"></CouponPop>
			<!-- 商品规格弹窗 -->
			<ProductWindow v-on:changeFun="changeFun" :attr="attr" :cartNum="cart_num"></ProductWindow>
			<!-- 分享海报 -->
			<StorePoster v-on:setPosterImageStatus="setPosterImageStatus" :posterImageStatus="posterImageStatus"
				:posterData="posterData" :goodId="id"></StorePoster>
			<!-- 分享弹窗 -->
			<ShareInfo v-on:setShareInfoStatus="setShareInfoStatus" :shareInfoStatus="shareInfoStatus"></ShareInfo>

			<view class="generate-posters acea-row row-middle on" v-if="posters">
				<view class="item" @click="setPosterImageStatus">
					<view class="iconfont icon-haibao"></view>
					<view>生成海报</view>
				</view>
			</view>
			<view class="generate-posters acea-row row-middle" v-if="!posters">
				<view class="item" @click="setPosterImageStatus">
					<view class="iconfont icon-haibao"></view>
					<view>生成海报</view>
				</view>
			</view>
			<view class="mask" @touchmove.prevent @click="listenerActionClose" v-show="posters"></view>
			<view class="posterCanvasWarp">
				<canvas class="posterCanvas" canvas-id="myCanvas"></canvas>
			</view>
		</view>


		<!-- 生成商品分享海报 -->
		<view v-if="canvasStatus" class="poster-first">
			<!-- <div class="posterCanvasWarp">
	    <canvas class="posterCanvas" canvas-id="myCanvas"></canvas>
	  </div> -->
			<!-- <view class="poster-pop">
	    <image
	      src="@/static/images/poster-close.png"
	      class="close"
	      @click="canvasStatus = false"
	    />
	  </view> -->
			<view class="poster-pop" v-show="canvasStatus">
				<img src="https://qny.yijiumy.com/poster-close.png" class="close" @click="canvasStatus = false"
					mode="widthFix" />

				<!-- #ifdef MP-WEIXIN -->
				<image :src="posterImage" alt="tp" class="poster-image" show-menu-by-longpress mode="widthFix" />
				<!--  #endif -->
				<!-- #ifdef APP-PLUS-->
				<image :src="posterImage" alt="tp" class="poster-image" @longpress="saveImage" mode="widthFix" />
				<!--  #endif -->
				<view class="keep">长按图片可以保存到手机</view>
			</view>
			<view class="mask"></view>
		</view>

		<l-painter ref="painter" isCanvasToTempFilePath @success="path = $event"
			custom-style="position: fixed; left: 200%"
			css="width: 750rpx; padding-bottom: 40rpx; background: linear-gradient(,#9f2b45 0%, #ed5e78 100%)">
			<l-painter-image :src="userInfo.avatar"
				css="margin-left: 40rpx; margin-top: 40rpx; width: 84rpx;  height: 84rpx; border-radius: 50%;" />
			<l-painter-view css="margin-top: 40rpx; padding-left: 20rpx; display: inline-block">
				<l-painter-text :text="userInfo.nickname"
					css="display: block; padding-bottom: 10rpx; color: #fff; font-size: 32rpx; fontWeight: bold" />
				<l-painter-text text="为您挑选了一个好物" css="color: rgba(255,255,255,.7); font-size: 24rpx" />
			</l-painter-view>
			<l-painter-view
				css="margin-left: 40rpx; margin-top: 30rpx; padding: 14rpx; box-sizing: border-box; background: #fff; border-radius: 16rpx; width: 670rpx; box-shadow: 0 20rpx 58rpx rgba(0,0,0,.15)">
				<l-painter-image :src="storeInfo.image"
					css="object-fit: cover; object-position: 50% 50%; width: 606rpx; height: 606rpx; border-radius: 12rpx;" />
				<l-painter-view
					css="margin-top: 32rpx; color: #FF0000; font-weight: bold; font-size: 28rpx; line-height: 1em;">
					<l-painter-text text="￥" css="vertical-align: bottom" />
					<l-painter-text :text="storeInfo.price" css="vertical-align: bottom; font-size: 58rpx" />
					<!-- <l-painter-text :text="'￥'+storeInfo.otPrice"
						css="vertical-align: bottom; padding-left: 10rpx; font-weight: normal; text-decoration: line-through; color: #999999" /> -->
				</l-painter-view>
				<l-painter-view css="margin-top: 32rpx; font-size: 26rpx; color: #8c5400">
					<!-- <l-painter-text v-if="!storeInfo.merId" text="直营" css="color: #212121; background: #ffb400;" /> -->
					<l-painter-text text="30天最低价"
						css="margin-left: 16rpx; background: #fff4d9;" />
					<l-painter-text text="满减优惠" css="margin-left: 16rpx; background: #fff4d9" />
					<l-painter-text text="超高好评" css="margin-left: 16rpx; background: #fff4d9" />
				</l-painter-view>
				<l-painter-view css="margin-top: 30rpx">
					<l-painter-text
						css="line-clamp: 2; color: #333333; line-height: 1.8em; font-size: 36rpx; width: 478rpx; padding-right:32rpx; box-sizing: border-box"
						:text="storeInfo.storeInfo"></l-painter-text>
					<l-painter-image :src="generate"
						css="width: 180rpx; height: 180rpx; position: absolute; right: 0; bottom: 2%; object-fit: contain; object-position: 50% 50%;" />
				</l-painter-view>
			</l-painter-view>
		</l-painter>









	</view>
</template>

<script>
	// import { swiper, swiperSlide } from "vue-awesome-swiper";

	import ProductConSwiper from "@/components/ProductConSwiper";
	import UserEvaluation from "@/components/UserEvaluation";
	import CouponPop from "@/components/CouponPop";
	import ProductWindow from "@/components/ProductWindow";
	import StorePoster from "@/components/StorePoster";
	import ShareInfo from "@/components/ShareInfo";
	import BussinessCard from "@/components/BusinessCard"
	import {
		getProductDetail,
		postCartAdd,
		getCartCount,
		getProductCode,
	} from "@/api/store";
	import {
		getCoupon,
		getCollectAdd,
		getCollectDel,
		getUserInfo,
		getGenerateCode
	} from "@/api/user";
	import cookie from "@/utils/store/cookie";
	import {
		isWeixin,
		PosterCanvas,
		handleQrCode,
		handleUrlParam,
		getCurrentPageUrlWithArgs
	} from "@/utils";
	import {
		wechatEvevt
	} from "@/libs/wechat";
	import {
		imageBase64
	} from "@/api/public";
	import {
		mapGetters
	} from "vuex";
	import {
		generateCode
	} from '@/utils/getGenerate'

	export default {
		name: "GoodsCon",
		components: {
			// swiper,
			// swiperSlide,
			ProductConSwiper,
			UserEvaluation,
			CouponPop,
			ProductWindow,
			StorePoster,
			ShareInfo,
			BussinessCard
		},
		data: function() {
			return {
				shareInfoStatus: false,
				weixinStatus: false,
				mapShow: false,
				merId: '',
				mapKey: "",
				posterData: {
					image: "",
					title: "",
					price: "",
					code: "",
				},
				BussinessDetails: {},
				posterImageStatus: false,
				animated: false,
				coupon: {
					coupon: false,
					list: [],
				},
				attr: {
					cartAttr: false,
					productAttr: [],
					productSelect: {},
				},
				isOpen: false, //是否打开属性组件
				productValue: [],
				id: 0,
				storeInfo: {},
				couponList: [],
				attrTxt: "请选择",
				attrValue: "",
				cart_num: 1, //购买数量
				replyCount: "",
				replyChance: "",
				reply: [],
				priceName: 0,
				CartCount: 0,
				posters: false,
				banner: [{}, {}],
				swiperRecommend: {
					pagination: {
						el: ".swiper-pagination",
						clickable: true,
					},
					autoplay: false,
					loop: false,
					speed: 1000,
					observer: true,
					observeParents: true,
				},
				goodList: [],
				// systemStore: {},
				qqmapsdk: null,
				productConClass: "product-con",
				tempName: "全国包邮",


				// 生成海报New
				path: '',
				generate: ``,
				posterImage: '',
				canvasStatus: false
			};
		},
		computed: mapGetters(["isLogin", "location", "userInfo"]),
		mounted: function() {
			this.$store.commit("get_to", "goodcon");
			let url = handleQrCode();
			if (!url) {
				url = handleUrlParam(getCurrentPageUrlWithArgs())
			}
			if (url && url.id) {
				this.id = url.id;
				let urlSpread = parseInt(url.spread);
				if (urlSpread) {
					cookie.set("spread", urlSpread);
				}
			} else {
				this.id = this._route.query.id;
			}
			this.productCon();
			this.setOpenShare();
		},
		watch: {
			posterImageStatus(status) {
				console.log(status);
				if (status) {
					this.productConClass = "noscroll product-con";
				} else {
					this.productConClass = "product-con";
				}
			},
		},
		methods: {
			saveImage() {
				uni.saveImageToPhotosAlbum({
					filePath: this.posterImage,
					success: function() {
						uni.showToast({
							title: '保存成功',
							icon: "none",
							duration: 2000
						});
					}
				});

			},
			_listenerActionSheet() {
				uni.showLoading({
					title: "生成海报中",
				});
				let _this = this
				this.$refs.painter.canvasToTempFilePathSync({
					// 在nvue里是jpeg
					fileType: "jpg",
					quality: 1,
					success: (res) => {
						console.log(res.tempFilePath);
						_this.posterImage = res.tempFilePath
						_this.canvasStatus = true
						uni.hideLoading();
						// 非H5 保存到相册
						// H5 提示用户长按图另存
						// uni.saveImageToPhotosAlbum({
						// 	filePath: res.tempFilePath,
						// 	success: function () {
						// 		console.log('save success');
						// 	}
						// });
					},
				})
			},
			onShareAppMessage: function() {
				// return {
				//   title: this.storeInfo.storeName,
				//   imageUrl: this.storeInfo.image,
				//   path: "pages/shop/GoodsCon/index?id=" + this.storeInfo.id + "&spread=" + uni.getStorageSync("uid") +
				//     "&pageType=good&codeType=routine",
				//   success(res) {
				//     uni.showToast({
				//       title: '分享成功'
				//     })
				//   },
				//   fail(res) {
				//     uni.showToast({
				//       title: '分享失败',
				//       icon: 'none'
				//     })
				//   }
				// }

				// 新的分享，分享带上商品id和用户uid
				// 参数：spread 用户uid
				// 参数：id 商品id
				return {
					title: this.storeInfo.storeName,
					imageUrl: this.storeInfo.image,
					path: "pages/shop/GoodsCon/index?id=" + this.storeInfo.id + "&spread=" + uni.getStorageSync(
						"uid") +
						"&pageType=good&codeType=routine",
					success(res) {
						uni.showToast({
							title: '分享成功'
						})
					},
					fail(res) {
						uni.showToast({
							title: '分享失败',
							icon: 'none'
						})
					}
				}
			},
			goHome() {
				this.$yrouter.reLaunch({
					path: "/pages/launch/index",
					query: {
						type: 'Business'
					}
				});
			},
			goShoppingCart() {
				this.$yrouter.reLaunch({
					path: "/pages/launch/index",
					query: {
						type: 'ShoppingCart'
					}
				});
			},
			goCustomerList() {
				this.$yrouter.push({
					path: "/userPack/pages/user/CustomerList/index",
				});
			},
			goStoreList() {
				this.$yrouter.push({
					path: "/pages/shop/StoreList/index",
				});
			},
			goEvaluateList(id) {
				this.$yrouter.push({
					path: "/pages/shop/EvaluateList/index",
					query: {
						id,
					},
				});
			},
			telPhone(phoneNumber) {
				uni.makePhoneCall({
					phoneNumber: phoneNumber,
					fail() {
						console.log("取消拨打");
					}
				});
			},
			updateTitle() {
				// document.title = this.storeInfo.storeName || this.$yroute.meta.title;
			},
			setShareInfoStatus: function() {
				this.shareInfoStatus = !this.shareInfoStatus;
				this.posters = false;
			},
			shareCode: function() {
				var that = this;
				getProductCode(that.id).then((res) => {
					that.posterData.code = res.data.code;
					that.listenerActionSheet();
				});
			},
			setPosterImageStatus: function() {
				this.posterImageStatus = !this.posterImageStatus;
				this.posters = false;
			},
			//产品详情接口；
			productCon: function() {
				let that = this;
				let from = this.location;
				if (this.$deviceType == "app") {
					from.from = "app";
				}
				uni.showLoading({
					title: "加载中",
					mask: true
				});
				getProductDetail(that.id, from)
					.then((res) => {
						res.data.storeInfo.description = res.data.storeInfo.description.replace(
							/\<img/gi,
							'<img style="max-width:100%;height:auto;"'
						);
						that.$set(that, "storeInfo", res.data.storeInfo);
						// 给 attr 赋值，将请求回来的规格赋值给 attr
						that.$set(that.attr, "productAttr", res.data.productAttr);
						that.$set(that, "productValue", res.data.productValue);
						that.$set(that, "replyCount", res.data.replyCount); // 用户评价
						that.$set(that, "replyChance", res.data.replyChance); // 好评率
						that.reply = res.data.reply ? [res.data.reply] : [];
						that.$set(that, "reply", that.reply);
						that.$set(that, "priceName", res.data.priceName);
						that.$set(that, "tempName", res.data.tempName);
						that.$set(that, "merId", res.data.merId);

						if (res.data.merId == 0) {
							that.$set(that, "BussinessDetails", res.data.systemStore);
						} else {
							that.$set(that, "BussinessDetails", res.data.systemMerStore);
						}


						that.posterData.image = that.storeInfo.image;
						if (that.storeInfo.storeName.length > 30) {
							that.posterData.title =
								that.storeInfo.storeName.substring(0, 30) + "...";
						} else {
							that.posterData.title = that.storeInfo.storeName;
						}
						that.posterData.price = that.storeInfo.price;
						that.posterData.code = that.storeInfo.codeBase;
						// that.systemStore = res.data.systemStore; // 门店信息
						let good_list = res.data.goodList || [];
						let goodArray = [];
						let count = Math.ceil(good_list.length / 6);
						for (let i = 0; i < count; i++) {
							var list = good_list.slice(i * 6, 6);
							if (list.length)
								goodArray.push({
									list: list,
								});
						}
						that.mapKay = res.data.mapKay;
						that.$set(that, "goodList", goodArray);
						that.updateTitle();
						that.DefaultSelect();
						that.getCartCount();


						// if (!this.userInfo.extensionCode) {
						// 	generateCode(`pages/Loading/index`).then(res => {
						// 		this.generate = res
						// 	})
						// } else {
						// 	console.log("extensionCode", this.userInfo.extensionCode)
						// 	this.generate = this.userInfo.extensionCode
						// }
						getGenerateCode(encodeURIComponent("pages/shop/GoodsCon/index?id=" + this.storeInfo.id +
							"&spread=" + uni.getStorageSync("uid") +
							"&pageType=good&codeType=routine")).then(res => {
							this.generate = res.data
						})
					})
					.catch((err) => {
						// console.log(err)
						uni.showToast({
							title: err.msg || err.response.data.msg || err.response.data.message,
							icon: "none",
							duration: 2000,
						});
					})
					.finally(() => {
						uni.hideLoading();
					});
			},
			//默认选中属性；
			DefaultSelect: function() {
				let productAttr = this.attr.productAttr;
				let value = [];
				for (let i = 0; i < productAttr.length; i++) {
					this.$set(productAttr[i], "index", 0);
					value.push(productAttr[i].attrValueArr[0]);
				}
				//sort();排序函数:数字-英文-汉字；
				let productSelect = this.productValue[value.sort().join(",")];
				if (productSelect && productAttr.length) {
					this.$set(
						this.attr.productSelect,
						"store_name",
						this.storeInfo.storeName
					);
					this.$set(this.attr.productSelect, "image", productSelect.image);

					// console.log("productSelect111111--->")
					// console.log(productSelect)
					console.log('this.attr.productSelect',this.attr.productSelect)
					// this.$set(this.attr.productSelect, "price", productSelect.price);
					

					this.$set(this.attr.productSelect, "stock", productSelect.stock);
					
					this.$set(this.attr.productSelect, "unique", productSelect.unique);
					this.$set(this.attr.productSelect, "cart_num", 1);
					this.$set(this, "attrValue", value.sort().join(","));
					this.$set(this, "attrTxt", "已选择");
					this.$set(this.attr.productSelect, "price", this.getFormatPrice(this.storeInfo.merId, this
						.storeInfo));
				} else if (!productSelect && productAttr.length) {
					this.$set(
						this.attr.productSelect,
						"store_name",
						this.storeInfo.storeName
					);
					this.$set(this.attr.productSelect, "image", this.storeInfo.image);
					// this.$set(this.attr.productSelect, "price", this.storeInfo.price);
					this.$set(this.attr.productSelect, "price", this.getFormatPrice(this.storeInfo.merId, this
						.storeInfo));



					this.$set(this.attr.productSelect, "stock", 0);
					this.$set(this.attr.productSelect, "unique", "");
					this.$set(this.attr.productSelect, "cart_num", 0);
					this.$set(this, "attrValue", "");
					this.$set(this, "attrTxt", "请选择");
				} else if (!productSelect && !productAttr.length) {
					this.$set(
						this.attr.productSelect,
						"store_name",
						this.storeInfo.storeName
					);
					this.$set(this.attr.productSelect, "image", this.storeInfo.image);
					// this.$set(this.attr.productSelect, "price", this.storeInfo.price);
					this.$set(this.attr.productSelect, "price", this.getFormatPrice(this.storeInfo.merId, this
						.storeInfo));


					this.$set(this.attr.productSelect, "stock", this.storeInfo.stock);
					this.$set(
						this.attr.productSelect,
						"unique",
						this.storeInfo.unique || ""
					);
					this.$set(this.attr.productSelect, "cart_num", 1);
					this.$set(this, "attrValue", "");
					this.$set(this, "attrTxt", "请选择");
				}
			},
			// 根据当前用户身份返回规格面板选择规格后展示的价格

			// 招商价：merchantsPrice 经商价：businessPrice 批发价： wholesalePrice 团购价： grouponPrice 会员价 price

			getFormatPrice(merId, obj) {
				const userInfo=this.userInfo
				console.log("处理不同角色金额返回值")
				console.log(obj)

				let formatPrice=0
				if(userInfo.roleIdentification=='investment'||userInfo.roleIdentification=='store_administrator'||(userInfo.roleIdentification=='marketing_personnel'&&userInfo.roleLevel==1) ){
					formatPrice=obj.merchantsPrice
				}
				if(userInfo.roleIdentification == 'dealer'||(userInfo.roleIdentification=='marketing_personnel'&&userInfo.roleLevel==2)){
					formatPrice=obj.businessPrice
				}
				if(userInfo.roleIdentification == 'wholesaler'||(userInfo.roleIdentification=='marketing_personnel'&&userInfo.roleLevel==3)){
					formatPrice=obj.wholesalePrice
				}
				if(userInfo.roleIdentification == 'group'||(userInfo.roleIdentification=='marketing_personnel'&&userInfo.roleLevel==4)){
					formatPrice=obj.grouponPrice
				}
				if(userInfo.roleIdentification == 'member'){
					formatPrice=obj.price
				}

				return formatPrice
		
			},
			//购物车；
			ChangeCartNum: function(changeValue) {
				//changeValue:是否 加|减
				//获取当前变动属性
				let productSelect = this.productValue[this.attrValue];
				//如果没有属性,赋值给商品默认库存
				if (productSelect === undefined && !this.attr.productAttr.length) {
					productSelect = this.attr.productSelect;
				}
				//无属性值即库存为0；不存在加减；
				if (productSelect === undefined) return;
				let stock = productSelect.stock || 0;
				let num = this.attr.productSelect;
				if (changeValue) {
					num.cart_num++;
					if (num.cart_num > stock) {
						this.$set(this.attr.productSelect, "cart_num", stock);
						this.$set(this, "cart_num", stock);
					} else {
						this.$set(this.attr.productSelect, "cart_num", num.cart_num);
						this.$set(this, "cart_num", num.cart_num);
					}
				} else {
					num.cart_num--;
					if (num.cart_num < 1) {
						this.$set(this.attr.productSelect, "cart_num", 1);
						this.$set(this, "cart_num", 1);
					} else {
						this.$set(this.attr.productSelect, "cart_num", num.cart_num);
						this.$set(this, "cart_num", num.cart_num);
					}
				}
			},
			//将父级向子集多次传送的函数合二为一；
			changeFun: function(opt) {
				if (typeof opt !== "object") opt = {};
				let action = opt.action || "";
				let value = opt.value === undefined ? "" : opt.value;
				this[action] && this[action](value);
			},
			//打开优惠券插件；
			couponTap: function() {
				let that = this;
				that.coupons();
				that.coupon.coupon = true;
			},
			changecoupon: function(msg) {
				this.coupon.coupon = msg;
				this.coupons();
			},
			currentcoupon: function(res) {
				let that = this;
				that.coupon.coupon = false;
				that.$set(that.coupon.list[res], "is_use", true);
			},
			//可领取优惠券接口；
			coupons: function() {
				let that = this,
					q = {
						page: 1,
						limit: 20,
					};
				getCoupon(q).then((res) => {
					that.$set(that, "couponList", res.data || []);
					that.$set(that.coupon, "list", res.data);
				});
			},
			//打开属性插件；
			selecAttrTap: function() {
				this.attr.cartAttr = true;
				this.isOpen = true;
			},
			changeattr: function(msg) {
				// 修改了规格
				console.log(msg);
				this.attr.cartAttr = msg;
				this.isOpen = false;
			},
			//选择属性；
			ChangeAttr: function(res) {
				// 修改了规格

				let productSelect = this.productValue[res.value];
				if (productSelect) {
					this.attr.productAttr[res.indexw].index = res.indexn;
					this.$set(this.attr.productSelect, "image", productSelect.image);

					// 选择规格返回的金额展示需要根据当前用户身份来获取不同字段
					// this.$set(this.attr.productSelect, "price", productSelect.price);
					this.$set(this.attr.productSelect, "price", this.getFormatPrice(this.storeInfo.merId,
						productSelect));


					this.$set(this.attr.productSelect, "stock", productSelect.stock);
					this.$set(this.attr.productSelect, "unique", productSelect.unique);
					this.$set(this.attr.productSelect, "cart_num", 1);
					this.$set(this, "attrValue", res.value);
					this.$set(this, "attrTxt", "已选择");
				} else {
					this.$set(this.attr.productSelect, "image", this.storeInfo.image);
					this.$set(this.attr.productSelect, "price", this.storeInfo.price);
					this.$set(this.attr.productSelect, "stock", 0);
					this.$set(this.attr.productSelect, "unique", "");
					this.$set(this.attr.productSelect, "cart_num", 0);
					this.$set(this, "attrValue", "");
					this.$set(this, "attrTxt", "请选择");
				}
			},
			//收藏商品
			setCollect: function() {
				let that = this,
					id = that.storeInfo.id,
					category = "collect";
				if (that.storeInfo.userCollect) {
					getCollectDel(id, category).then(function() {
						that.storeInfo.userCollect = !that.storeInfo.userCollect;
					});
				} else {
					getCollectAdd(id, category).then(function() {
						that.storeInfo.userCollect = !that.storeInfo.userCollect;
					});
				}
			},
			//  点击加入购物车按钮
			joinCart: function() {
				//0=加入购物车
				this.goCat(0);
			},
			// 加入购物车；
			goCat: function(news) {
				let that = this,
					productSelect = that.productValue[this.attrValue];
				//打开属性
				if (that.attrValue) {
					//默认选中了属性，但是没有打开过属性弹窗还是自动打开让用户查看默认选中的属性
					that.attr.cartAttr = !that.isOpen ? true : false;
				} else {
					if (that.isOpen) that.attr.cartAttr = true;
					else that.attr.cartAttr = !that.attr.cartAttr;
				}
				//只有关闭属性弹窗时进行加入购物车
				if (that.attr.cartAttr === true && that.isOpen === false)
					return (that.isOpen = true);
				//如果有属性,没有选择,提示用户选择
				if (
					that.attr.productAttr.length &&
					productSelect === undefined &&
					that.isOpen === true
				) {
					uni.showToast({
						title: "产品库存不足，请选择其它",
						icon: "none",
						duration: 2000,
					});
					return;
				}
				let q = {
					productId: that.id,
					cartNum: that.attr.productSelect.cart_num,
					new: news,
					uniqueId: that.attr.productSelect !== undefined ?
						that.attr.productSelect.unique : "",
				};
				console.log("postCartAdd")
				console.log(q)
				postCartAdd(q)
					.then(function(res) {
						that.isOpen = false;
						that.attr.cartAttr = false;
						if (news) {
							that.$yrouter.push({
								path: "/userOrderPack/pages/order/OrderSubmission/index",
								query: {
									id: res.data.cartId,
									// 将是否直营传递到提交订单页面做页面展示
									merId: that.storeInfo.merId
								},
							});
						} else {
							uni.showToast({
								title: "添加购物车成功",
								icon: "success",
								duration: 2000,
								complete: () => {
									that.getCartCount(true);
								},
							});
						}
					})
					.catch((error) => {
						that.isOpen = false;
						uni.showToast({
							title: error.response.data.msg,
							icon: "none",
							duration: 2000,
						});
					});
			},
			//获取购物车数量
			getCartCount: function(isAnima) {
				let that = this;
				const isLogin = that.isLogin;
				if (isLogin) {
					getCartCount({
						numType: 0,
					}).then((res) => {
						that.CartCount = res.data.count;
						//加入购物车后重置属性
						if (isAnima) {
							that.animated = true;
							setTimeout(function() {
								that.animated = false;
							}, 500);
						}
					});
				}
			},
			//立即购买；
			tapBuy: function() {
				//  1=直接购买
				this.goCat(1);
			},
			listenerActionSheet: function() {
				if (isWeixin() === true) {
					this.weixinStatus = true;
				}
				this.posters = true;
			},
			listenerActionClose: function() {
				this.posters = false;
			},
			setOpenShare: function() {
				var data = this.storeInfo;
				var href = this.location.href;
				if (this.$deviceType == "weixin") {
					if (this.isLogin) {
						getUserInfo().then((res) => {
							href =
								href.indexOf("?") === -1 ?
								href + "?spread=" + res.data.uid :
								href + "&spread=" + res.data.uid;
							var configAppMessage = {
								desc: data.storeInfo,
								title: data.storeName,
								link: href,
								imgUrl: data.image,
							};
							wechatEvevt(
									["updateAppMessageShareData", "updateTimelineShareData"],
									configAppMessage
								)
								.then((res) => {

								})
								.catch((res) => {

									if (res.is_ready) {
										res.wx.updateAppMessageShareData(configAppMessage);
										res.wx.updateTimelineShareData(configAppMessage);
									}
								});
						});
					} else {
						var configAppMessage = {
							desc: data.storeInfo,
							title: data.storeName,
							link: href,
							imgUrl: data.image,
						};
						wechatEvevt(
								["updateAppMessageShareData", "updateTimelineShareData"],
								configAppMessage
							)
							.then((res) => {

							})
							.catch((res) => {

								if (res.is_ready) {
									res.wx.updateAppMessageShareData(configAppMessage);
									res.wx.updateTimelineShareData(configAppMessage);
								}
							});
					}
				}
			},
		},
	};
</script>


<style scoped lang="less">
	.geoPage {
		position: fixed;
		width: 100%;
		height: 100%;
		top: 0;
		z-index: 10000;
	}

	.product-con .store-info {
		margin-top: 0.2 * 100rpx;
		background-color: #fff;
	}

	.product-con .store-info .title {
		padding: 0 0.3 * 100rpx;
		font-size: 0.28 * 100rpx;
		color: #282828;
		height: 0.8 * 100rpx;
		line-height: 0.8 * 100rpx;
		border-bottom: 0.01 * 100rpx solid #f5f5f5;
	}

	.product-con .store-info .info {
		padding: 0 0.3 * 100rpx;
		height: 1.26 * 100rpx;
	}

	.product-con .store-info .info .picTxt {
		width: 100%;
		display: flex;
		align-items: center;
	}

	.product-con .store-info .info .picTxt .pictrue {
		width: 0.76 * 100rpx;
		height: 0.76 * 100rpx;
		margin-right: 0.2 * 100rpx;
	}

	.product-con .store-info .info .picTxt .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 0.06 * 100rpx;
	}

	.product-con .store-info .info .picTxt .text {
		flex: 1;
	}

	.product-con .store-info .info .picTxt .text .name {
		font-size: 0.3 * 100rpx;
		color: #282828;
	}

	.product-con .store-info .info .picTxt .text .address {
		font-size: 0.24 * 100rpx;
		color: #666;
		margin-top: 0.03 * 100rpx;
	}

	.product-con .store-info .info .picTxt .text .address .iconfont {
		color: #707070;
		font-size: 0.18 * 100rpx;
		margin-left: 0.1 * 100rpx;
	}

	.product-con .store-info .info .picTxt .addressBox {
		display: flex;
		flex-direction: column;
		align-items: flex-end;
	}

	.product-con .store-info .info .picTxt .addressBox .iconfont {
		font-size: 0.4 * 100rpx;
	}

	.product-con .store-info .info .picTxt .addressBox .addressTxt {
		font-size: 0.24 * 100rpx;
		color: #9f2b45;
	}

	.product-con .store-info .praise {
		font-size: 0.28 * 100rpx;
		color: #808080;
	}

	.product-con .store-info .praise .iconfont {
		font-size: 0.28 * 100rpx;
	}

	.product-con .superior {
		background-color: #fff;
		margin-top: 0.2 * 100rpx;
	}

	.product-con .superior .title {
		height: 0.98 * 100rpx;
	}

	.product-con .superior .title image {
		width: 0.3 * 100rpx;
		height: 0.3 * 100rpx;
	}

	.product-con .superior .title .titleTxt {
		margin: 0 0.2 * 100rpx;
		font-size: 0.3 * 100rpx;
		background-image: linear-gradient(to right, #f57a37 0%, #f21b07 100%);
		background-image: -webkit-linear-gradient(to right, #f57a37 0%, #f21b07 100%);
		background-image: -moz-linear-gradient(to right, #f57a37 0%, #f21b07 100%);
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
	}

	.product-con .superior .slider-banner {
		width: 6.9 * 100rpx;
		margin: 0 auto;
		padding-bottom: 0.2 * 100rpx;
	}

	.product-con .superior .slider-banner .list {
		width: 100%;
		padding-bottom: 0.2 * 100rpx;
	}

	.product-con .superior .slider-banner .list .item {
		width: 2.15 * 100rpx;
		margin: 0 0.22 * 100rpx 0.3 * 100rpx 0;
		font-size: 0.26 * 100rpx;
	}

	.product-con .superior .slider-banner .list .item:nth-of-type(3n) {
		margin-right: 0;
	}

	.product-con .superior .slider-banner .list .item .pictrue {
		width: 100%;
		height: 2.15 * 100rpx;
	}

	.product-con .superior .slider-banner .list .item .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 0.06 * 100rpx;
	}

	.product-con .superior .slider-banner .list .item .name {
		color: #282828;
		margin-top: 0.12 * 100rpx;
	}

	.product-con .superior .slider-banner .swiper-pagination-bullet {
		background-color: #999;
	}

	.product-con .superior .slider-banner .swiper-pagination-bullet-active {
		background-color: #e93323;
	}

	.mask {
		-webkit-filter: blur(2px);
		-moz-filter: blur(2px);
		-ms-filter: blur(2px);
		filter: blur(2px);
	}



	.product-con .product-intro .conter view {
		width: 100% !important;
	}

	.generate-posters {
		width: 100%;
		height: 1.7 * 100rpx;
		background-color: #fff;
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 99;
		transform: translate3d(0, 100%, 0);
		-webkit-transform: translate3d(0, 100%, 0);
		-ms-transform: translate3d(0, 100%, 0);
		-moz-transform: translate3d(0, 100%, 0);
		-o-transform: translate3d(0, 100%, 0);
		transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
		-webkit-transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
		-moz-transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
		-o-transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
	}

	.generate-posters.on {
		transform: translate3d(0, 0, 0);
		-webkit-transform: translate3d(0, 0, 0);
		-ms-transform: translate3d(0, 0, 0);
		-moz-transform: translate3d(0, 0, 0);
		-o-transform: translate3d(0, 0, 0);
	}

	.generate-posters .item {
		flex: 50%;
		-webkit-flex: 50%;
		-ms-flex: 50%;
		text-align: center;
	}

	.generate-posters .item .iconfont {
		font-size: 0.8 * 100rpx;
		color: #5eae72;
	}

	.generate-posters .item .iconfont.icon-haibao {
		color: #5391f1;
	}

	.noscroll {
		height: 100%;
		overflow: hidden;
	}


	// 分享太阳码
	.poster-first {
		overscroll-behavior: contain;
	}

	.poster-pop {
		// width: 4.5 * 100rpx;
		// height: 8 * 100rpx;
		width: 650rpx;
		position: fixed;
		left: 50%;
		transform: translateX(-50%);
		z-index: 99;
		top: 50%;
		margin-top: -4.6 * 100rpx;
	}

	.poster-pop .canvas {
		background-color: #ffffff;
		height: 8 * 100rpx;
	}

	.poster-pop .poster-image {
		width: 100%;
		height: auto;
	}

	.poster-pop .canvas .image {
		width: 4.5 * 100rpx;
		height: 4.5 * 100rpx;
		display: block;
	}

	.poster-pop .canvas .text {
		text-align: center;
		color: #000000;
		margin-top: 0.32 * 100rpx;
	}

	.poster-pop .canvas .text.black {
		height: 0.68 * 100rpx;
	}

	.poster-pop .canvas .text.rad {
		color: #ff0000;
	}

	.poster-pop .canvas .code {
		height: 1.4 * 100rpx;
		display: flex;
	}

	.poster-pop .canvas .code .code-img {
		width: 33%;
		padding: 0.06 * 100rpx;
	}

	.poster-pop .canvas .code .code-img image {
		width: 100%;
	}

	.poster-pop .canvas .code .code-text {
		width: 60%;
		font-size: 0.12 * 100rpx;
		line-height: 1.64 * 100rpx;
	}

	.poster-pop .close {
		width: 0.46 * 100rpx;
		height: 0.75 * 100rpx;
		position: fixed;
		right: 0;
		top: -0.73 * 100rpx;
		display: block;
	}

	.poster-pop .save-poster {
		background-color: #df2d0a;
		font-size: 0.22 * 100rpx;
		color: #fff;
		text-align: center;
		height: 0.76 * 100rpx;
		line-height: 0.76 * 100rpx;
		width: 100%;
		margin-top: -0.04 * 100rpx;
	}

	.poster-pop .keep {
		color: #fff;
		text-align: center;
		font-size: 0.25 * 100rpx;
		margin-top: 0.1 * 100rpx;
	}

	.mask {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: rgba(0, 0, 0, 0.6);
		z-index: 12;
	}
</style>